﻿<UserControl x:Class="FacebookClient.UpdateStatusControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:FacebookClient="clr-namespace:FacebookClient"
    xmlns:ClientManager="clr-namespace:ClientManager" 
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls">
  <UserControl.Template>
    <ControlTemplate TargetType="{x:Type FacebookClient:UpdateStatusControl}">
      <ControlTemplate.Resources>
        <FacebookClient:IsStringNullOrWhitespaceConverter x:Key="IsStringNullOrWhitespaceConverter" />

        <Style x:Key="GlowButtonStyle" TargetType="{x:Type ButtonBase}">
          <Setter Property="FontFamily" Value="{DynamicResource SansSerifFont}" />
          <Setter Property="FontSize" Value="{DynamicResource SmallFontSize1}" />
          <Setter Property="Foreground" Value="White" />
          <Setter Property="FontWeight" Value="Bold" />
          <Setter Property="Margin" Value="5"/>
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type ButtonBase}">
                <Border Background="#00FFFFFF">
                  <ContentPresenter/>
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
          <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="Effect">
                <Setter.Value>
                  <DropShadowEffect Color="White" BlurRadius="2" ShadowDepth="0" />
                </Setter.Value>
              </Setter>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Opacity" Value="0.5" />
            </Trigger>
          </Style.Triggers>
        </Style>

        <ControlTemplate x:Key="UpdateBoxAttachmentButtonTemplate" TargetType="{x:Type ButtonBase}">
          <Grid x:Name="Root">
            <TextBlock x:Name="Glow"
                FontSize="{DynamicResource SmallFontSize1}"
                FontFamily="{DynamicResource SansSerifFont}"
                FontWeight="Medium"
                Text="{TemplateBinding Content}"
                Foreground="White" Opacity="0">
              <TextBlock.Effect>
                <BlurEffect KernelType="Gaussian" Radius="8" />
              </TextBlock.Effect>
            </TextBlock>
            <TextBlock x:Name="Main"
                FontSize="{DynamicResource SmallFontSize1}"
                FontFamily="{DynamicResource SansSerifFont}"
                FontWeight="Medium"
                Text="{TemplateBinding Content}"
                Foreground="White"/>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Opacity" TargetName="Main" Value=".5" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="Opacity" TargetName ="Glow" Value="1" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
              <Setter Property="Opacity" TargetName="Glow" Value="1" />
              <Setter Property="Opacity" TargetName="Main" Value="0.7" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>

        <Style x:Key="UpdateBoxAttachmentButtonStyle" TargetType="{x:Type ButtonBase}">
          <Setter Property="Template" Value="{StaticResource UpdateBoxAttachmentButtonTemplate}" />
          <Setter Property="Focusable" Value="False" />
          <Setter Property="Cursor" Value="Hand" />
        </Style>
      </ControlTemplate.Resources>
      <Border HorizontalAlignment="Center" x:Name="StatusBorder" Background="{DynamicResource UpdateStatusControlBrush}" BorderThickness="0" CornerRadius="8">
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
          </Grid.RowDefinitions>

          <FacebookClient:CommandTextBox Grid.Row="0" x:Name="PART_ShareTextBox" BannerText="What's on your mind?"
                        Style="{DynamicResource StatusTextBoxStyle}" HorizontalAlignment="Left" Margin="5"
                        CommitCommand="{x:Static FacebookClient:UpdateStatusControl.UpdateStatusCommand}"/>

          <Border Grid.Row="1" Panel.ZIndex="1" x:Name="BottomPanel" BorderBrush="Transparent" BorderThickness="2,0,2,2" Margin="-2,-1,0,0" CornerRadius="0,0,8,8" 
                            Visibility="Collapsed"
                  DataContext="{Binding ElementName=PART_ShareTextBox}">
            <StackPanel>
              <Grid x:Name="AttachPanel"  Visibility="Visible" Opacity="1">
                <Grid.RowDefinitions>
                  <RowDefinition Height="*"/>
                  <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <DockPanel Grid.Row="0">
                  <Button x:Name="ShareButton"
                          DockPanel.Dock="Right" 
                          Command="{x:Static FacebookClient:UpdateStatusControl.UpdateStatusCommand}"
                          VerticalAlignment="Bottom"
                          HorizontalAlignment="Right" 
                          Margin="0,3,8,5"
                          Height="22"
                          IsEnabled="{Binding Path=Text, Converter={StaticResource IsStringNullOrWhitespaceConverter}, ConverterParameter=Inverse}"
                          Style="{DynamicResource StandardButtonStyle}">
                    Share
                  </Button>
                  <WrapPanel Orientation="Horizontal" DockPanel.Dock="Left" Margin="10,3">
                    <Button x:Name="LinkButton" Content="Attach Link" Margin="0,0,10,0" HorizontalAlignment="Left" 
                                                Style="{StaticResource UpdateBoxAttachmentButtonStyle}" 
                                                Focusable="False" Click="OnLinkButtonClick" VerticalAlignment="Center"/>
                    <Button x:Name="PhotoButton" Content="Attach Photo" Style="{StaticResource UpdateBoxAttachmentButtonStyle}" 
                                                Focusable="False" VerticalAlignment="Center" Click="OnPhotoButtonClick"/>
                  </WrapPanel>
                </DockPanel>

                <StackPanel Grid.Row="1" x:Name="LinkModePanel" Visibility="Collapsed">
                  <FacebookClient:CommandTextBox x:Name="PART_LinkTextBox" Style="{DynamicResource ApplicationBarShareTextBoxStyle}"
                                            Margin="5" CommitCommand="{x:Static FacebookClient:UpdateStatusControl.UpdateStatusCommand}"
                                            SpellCheck.IsEnabled="False" Tag="http://" />
                  <Button 
                    Content="Share"
                    Command="{x:Static FacebookClient:UpdateStatusControl.UpdateStatusCommand}"
                    Height="22"
                    HorizontalAlignment="Right" 
                    Margin="0,5,8,5"
                    Style="{DynamicResource StandardButtonStyle}"
                    IsEnabled="{Binding Path=Text, Converter={StaticResource IsStringNullOrWhitespaceConverter}, ConverterParameter=Inverse}" />
                </StackPanel>

                <DockPanel Grid.Row="1" x:Name="PhotoModePanel" Visibility="Collapsed">
                  <Button DockPanel.Dock="Right" 
                          Content="Share" 
                          Command="{x:Static FacebookClient:UpdateStatusControl.UpdateStatusCommand}"
                          HorizontalAlignment="Right" 
                          VerticalAlignment="Bottom" 
                          Margin="0,5,8,5"
                          Height="22"
                          Style="{DynamicResource StandardButtonStyle}"
                          IsEnabled="{Binding Path=Text, Converter={StaticResource IsStringNullOrWhitespaceConverter}, ConverterParameter=Inverse}" />
                  <Image Grid.Row="1" x:Name="PART_PhotoImage" MaxHeight="100" HorizontalAlignment="Left" Margin="10"/>
                </DockPanel>
              </Grid>
            </StackPanel>
          </Border>
        </Grid>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="DisplayMode" Value="Link">
          <Setter TargetName="LinkModePanel" Property="Visibility" Value="Visible"/>
          <Setter TargetName="ShareButton" Property="Visibility" Value="Collapsed"/>
          <Setter TargetName="LinkButton" Property="Content" Value="Remove Link"/>
          <Setter TargetName="PhotoButton" Property="Visibility" Value="Collapsed"/>
        </Trigger>
        <Trigger Property="DisplayMode" Value="Photo">
          <Setter TargetName="PhotoModePanel" Property="Visibility" Value="Visible"/>
          <Setter TargetName="ShareButton" Property="Visibility" Value="Collapsed"/>
          <Setter TargetName="LinkButton" Property="Visibility" Value="Collapsed"/>
          <Setter TargetName="PhotoButton" Property="Content" Value="Remove Photo"/>
        </Trigger>
        <Trigger Property="IsActive" Value="True">
          <Trigger.EnterActions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation Storyboard.TargetName="StatusBorder" Storyboard.TargetProperty="(Border.Background).(Brush.Opacity)" To="1" Duration="0:0:1"/>
              </Storyboard>
            </BeginStoryboard>
          </Trigger.EnterActions>
          <Trigger.ExitActions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation Storyboard.TargetName="StatusBorder" Storyboard.TargetProperty="(Border.Background).(Brush.Opacity)" To="0" Duration="0:0:1"/>
              </Storyboard>
            </BeginStoryboard>
          </Trigger.ExitActions>

          <Setter TargetName="PART_ShareTextBox" Property="MinHeight" Value="38"/>
          <Setter TargetName="PART_ShareTextBox" Property="MaxHeight" Value="{x:Static System:Double.PositiveInfinity}"/>
          <Setter TargetName="BottomPanel" Property="Visibility" Value="Visible"/>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </UserControl.Template>

</UserControl>
